package astar;

public class Node {

	public int x, y;
	public double g,h;
	
	private int hash;
	private Node parent;
	private int parentsCount;
	
	public Node(int x, int y) {
		this(x,y,-1,-1);
	}
	
	Node(int x, int y, float g, float h) {
		this.x = x;
		this.y = y;
		this.g = g;
		this.h = h;
		hash = 7;
		hash = 71 * hash + x;
		hash = 71 * hash + y;
	}
	
	public double getF() {
		return g+h;
	}
	
	public int getParentsCount() {
		return parentsCount;
	}
	
	public void setParent(Node node) {
		this.parent = node;
		this.parentsCount = node.getParentsCount()+1;
	}
	
	public Node getParent() {
		return parent;
	}
	
	@Override
	public boolean equals(Object o) {
		return o!=null && this.hash == o.hashCode();
	}
	
	@Override
	public int hashCode() {
		return hash;
	}
	
	public String toString() {
		return "||("+this.x+","+this.y+") "+this.g+"|"+this.h+"|"+this.getF();
	}
}
